/*
ID: wxm071
PROG: gift1
LANG: C++14
*/
#include <map>
#include <string>
#include <vector>
#include <fstream>
#include <iostream>
#include<algorithm>

using namespace std;

int main(int argc, char const *argv[])
{
    ifstream ifs("gift1.in");
    
    int np = 0;
    ifs >> np;
    
    vector<string> names;

    map<string, int> group;

    for(int i = 0; i < np; ++i){
        string name;
        ifs >> name;
        names.push_back(name);
        group[name] = 0;
    }

    while(!ifs.eof()){
        string giver;
        ifs >> giver;

        int money = 0,ng = 0;
        ifs >> money >> ng;

        if(ng != 0){
            int gift = money / ng;
            group[giver] -= money;
            for(int i = 0; i < ng; ++i){
                string receiver;
                ifs >> receiver;
                group[receiver] += gift;
            }
        group[giver] += money % ng;   
        }
        else{
            group[giver] += money;
        }
    }
    ofstream ofs("gift1.out");
    for(string name : names){
        ofs << name << " " << group[name] << endl;
    }    
    return 0;
}
